import {getRequest, postRequest} from "@/utils/request.js";

/**
 * 发送评论
 * @param type 1:文章评论，2：评论评论
 * @param targetId 品论媒体对象(视频、文章)的ID
 * @param fatherId 父级评论ID，如果为 '' 则表示是一级评论
 * @param toCommentId 回复评论的评论对象的commentId
 * @param content 评论内容
 * @param time 评论时间
 * @returns {Promise<unknown>}
 */
export async function sendCommentReq(type, targetId, fatherId, toCommentId, content, time = new Date()) {
    try {
        return await postRequest('/heaven-server/comment/auth/send', {type, targetId, fatherId, toCommentId, content, time});
    } catch (e) {
        console.log('评论失败',e);
        return {code: -1, msg: `评论失败-${e.message}`}
    }
}

/**
 * 加载评论
 * @param targetId 品论媒体对象(视频、文章)的ID
 * @param type 1:视频评论，2：文帖评论
 * @param sort time:最新；hot：最热
 * @param page 页码
 * @param size 页大小
 * @returns {Promise<unknown>}
 */
export async function loadCommentReq(targetId, type, sort, page, size = 10) {
    try {
        return await getRequest('/heaven-server/comment/load', {targetId,type,sort,page,size});
    } catch (e) {
        console.log('获取评论失败',e);
        return {code: -1, msg: `获取评论失败-${e.message}`}
    }
}

export async function likeDisLikeReq(commentId, type) {
    try {
        return await getRequest('/heaven-server/comment/auth/like-dislike', {commentId, type});
    } catch (e) {
        console.log('点赞评论失败',e);
        return {code: -1, msg: `点赞评论失败-${e.message}`}
    }
}